﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ControleEstoque.PDA
{
	public enum ButtonsMode
	{
		None = 0, Inserting = 1, Editing = 2, Listing = 3, ListItemSelected = 4
	}

	public partial class Buttons : UserControl
	{
		ButtonsMode _mode;

		public ButtonsMode Mode
		{
			get
			{
				return _mode;
			}
			set
			{
				_mode = value;

				switch (_mode)
				{
					case ButtonsMode.None:
						this.DeleteVisible = false;
						this.CancelVisible = false;
						this.UpdateVisible = false;
						this.EditVisible = false;
						this.InsertVisible = false;
						this.ClearVisible = false;
						break;
					case ButtonsMode.Inserting:
						this.DeleteVisible = false;
						this.CancelVisible = false;
						this.UpdateVisible = false;
						this.EditVisible = false;
						this.InsertVisible = true;
						this.ClearVisible = true;
						break;
					case ButtonsMode.Editing:
						this.DeleteVisible = false;
						this.CancelVisible = true;
						this.UpdateVisible = true;
						this.EditVisible = false;
						this.InsertVisible = false;
						this.ClearVisible = false;
						break;
					case ButtonsMode.Listing:
						this.DeleteVisible = false;
						this.CancelVisible = false;
						this.UpdateVisible = false;
						this.EditVisible = false;
						this.InsertVisible = true;
						this.ClearVisible = false;
						break;
					case ButtonsMode.ListItemSelected:
						this.DeleteVisible = true;
						this.CancelVisible = false;
						this.UpdateVisible = false;
						this.EditVisible = true;
						this.InsertVisible = true;
						this.ClearVisible = false;
						break;
				}
			}
		}

		public bool EditVisible
		{
			get
			{
				return pbEdit.Visible;
			}
			set
			{
				pbEdit.Visible = value;
			}
		}

		public bool UpdateVisible
		{
			get
			{
				return pbUpdate.Visible;
			}
			set
			{
				pbUpdate.Visible = value;
			}
		}

		public bool InsertVisible
		{
			get
			{
				return pbInsert.Visible;
			}
			set
			{
				pbInsert.Visible = value;
			}
		}

		public bool DeleteVisible
		{
			get
			{
				return pbDelete.Visible;
			}
			set
			{
				pbDelete.Visible = value;
			}
		}

		public bool CancelVisible
		{
			get
			{
				return pbCancel.Visible;
			}
			set
			{
				pbCancel.Visible = value;
			}
		}

		public bool ClearVisible
		{
			get
			{
				return pbClean.Visible;
			}
			set
			{
				pbClean.Visible = value;
			}
		}

		public Buttons()
		{
			InitializeComponent();
		}

		private void pbEdit_Click(object sender, EventArgs e)
		{
			OnEditAction(e);
		}

		private void pbInsert_Click(object sender, EventArgs e)
		{
			OnInsertAction(e);
		}

		private void pbUpdate_Click(object sender, EventArgs e)
		{
			OnUpdateAction(e);
		}

		private void pbCancel_Click(object sender, EventArgs e)
		{
			OnCancelAction(e);
		}

		private void pbDelete_Click(object sender, EventArgs e)
		{
			OnDeleteAction(e);
		}

		private void pbClear_Click(object sender, EventArgs e)
		{
			OnClearAction(e);
		}

		public event EventHandler ClearAction;
		public event EventHandler InsertAction;
		public event EventHandler UpdateAction;
		public event EventHandler DeleteAction;
		public event EventHandler CancelAction;
		public event EventHandler EditAction;

		protected void OnClearAction(EventArgs e)
		{
			if (ClearAction != null)
			{
				ClearAction(this, e);
			}
		}

		protected void OnInsertAction(EventArgs e)
		{
			if (InsertAction != null)
			{
				InsertAction(this, e);
			}
		}

		protected void OnUpdateAction(EventArgs e)
		{
			if (UpdateAction != null)
			{
				UpdateAction(this, e);
			}
		}

		protected void OnDeleteAction(EventArgs e)
		{
			if (DeleteAction != null)
			{
				DeleteAction(this, e);
			}
		}

		protected void OnCancelAction(EventArgs e)
		{
			if (CancelAction != null)
			{
				CancelAction(this, e);
			}
		}

		protected void OnEditAction(EventArgs e)
		{
			if (EditAction != null)
			{
				EditAction(this, e);
			}
		}
	}
}
